<template>
  <view class="demo-container">
    <view class="header">
      <text class="title">lsd-seamless-scroll 演示</text>
      <text class="subtitle">高性能无缝滚动组件</text>
    </view>
    
    <view class="demo-section">
      <text class="section-title">基础用法</text>
      <lsd-seamless-scroll 
        :list="commissionList" 
        :speed="40" 
        :height="120"
        class="demo-scroll"
      />
    </view>
    
    <view class="demo-section">
      <text class="section-title">自定义内容</text>
      <lsd-seamless-scroll 
        :list="customList" 
        :speed="50" 
        :height="150"
        :itemHeight="50"
        class="demo-scroll custom"
      >
        <template #item="{ item, index }">
          <view class="custom-item">
            <image :src="item.avatar" class="avatar" />
            <view class="info">
              <text class="name">{{ item.name }}</text>
              <text class="time">{{ item.time }}</text>
            </view>
            <text class="amount">+¥{{ item.amount }}</text>
          </view>
        </template>
      </lsd-seamless-scroll>
    </view>
    
    <view class="demo-section">
      <text class="section-title">控制面板</text>
      <view class="control-panel">
        <button @click="changeDirection" class="control-btn">
          切换方向: {{ direction === 'up' ? '向上' : '向下' }}
        </button>
        <button @click="changeSpeed" class="control-btn">
          速度: {{ speed }}px/s
        </button>
        <button @click="togglePlay" class="control-btn">
          {{ isPlaying ? '暂停' : '播放' }}
        </button>
      </view>
      
      <lsd-seamless-scroll 
        ref="scrollRef"
        :list="controlList" 
        :speed="speed" 
        :direction="direction"
        :autoPlay="false"
        :height="100"
        class="demo-scroll"
        @scroll-start="onScrollStart"
        @scroll-pause="onScrollPause"
      />
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      commissionList: [
        '用户189***4321 获得佣金 ¥15.80',
        '用户156***7890 获得佣金 ¥28.50',
        '用户138***1234 获得佣金 ¥12.00',
        '用户151***5678 获得佣金 ¥35.20',
        '用户139***9012 获得佣金 ¥19.90',
        '用户187***3456 获得佣金 ¥42.10'
      ],
      customList: [
        { 
          avatar: '/static/avatar1.png', 
          name: '张小明', 
          time: '2分钟前', 
          amount: '15.80' 
        },
        { 
          avatar: '/static/avatar2.png', 
          name: '李小红', 
          time: '5分钟前', 
          amount: '28.50' 
        },
        { 
          avatar: '/static/avatar3.png', 
          name: '王大力', 
          time: '8分钟前', 
          amount: '12.00' 
        }
      ],
      controlList: [
        '可控滚动项 1',
        '可控滚动项 2', 
        '可控滚动项 3',
        '可控滚动项 4',
        '可控滚动项 5'
      ],
      speed: 60,
      direction: 'up',
      isPlaying: false
    }
  },
  methods: {
    changeDirection() {
      this.direction = this.direction === 'up' ? 'down' : 'up'
    },
    changeSpeed() {
      this.speed = this.speed === 60 ? 30 : this.speed === 30 ? 90 : 60
    },
    togglePlay() {
      if (this.isPlaying) {
        this.$refs.scrollRef.pause()
      } else {
        this.$refs.scrollRef.play()
      }
      this.isPlaying = !this.isPlaying
    },
    onScrollStart() {
      console.log('滚动开始')
      this.isPlaying = true
    },
    onScrollPause() {
      console.log('滚动暂停')
      this.isPlaying = false
    }
  }
}
</script>

<style scoped>
.demo-container {
  padding: 20px;
  background: #f5f5f5;
  min-height: 100vh;
}

.header {
  text-align: center;
  margin-bottom: 30px;
}

.title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 14px;
  color: #666;
}

.demo-section {
  margin-bottom: 30px;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 12px;
}

.demo-scroll {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
}

.demo-scroll.custom {
  border-color: #1890ff;
}

.control-panel {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.control-btn {
  flex: 1;
  min-width: 100px;
  height: 36px;
  line-height: 36px;
  font-size: 12px;
  background: #1890ff;
  color: white;
  border: none;
  border-radius: 6px;
}

.control-btn:active {
  background: #096dd9;
}

.custom-item {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 50px;
  border-bottom: 1px solid #f0f0f0;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e0e0e0;
  margin-right: 12px;
}

.info {
  flex: 1;
}

.name {
  display: block;
  font-size: 14px;
  color: #333;
  margin-bottom: 2px;
}

.time {
  font-size: 12px;
  color: #999;
}

.amount {
  font-size: 14px;
  font-weight: bold;
  color: #ff4d4f;
}
</style>